package com.spring.factory;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 单例池
 */
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {
    private DefaultSingletonBeanRegistry() {
    }

    private static DefaultSingletonBeanRegistry defaultSingletonBeanRegistry = new DefaultSingletonBeanRegistry();

    private Map<String, Object> singletons = new HashMap<String, Object>();

    public static DefaultSingletonBeanRegistry getInstance() {
        return defaultSingletonBeanRegistry;
    }


    public void registerSingleton(String key, Object value) {
        singletons.put(key, value);
    }

    public Object getSingleton(String key) {
        return singletons.get(key);
    }

    public Collection<Object> getSingletonAll(){
        Collection<Object> values = singletons.values();
        return values;
    }
}
